#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import wx
            
class Non_Empty(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)
        
    def Clone(self):
        return Non_Empty()
    
    def Validate(self,win):
        textCtrl=self.GetWindow()
        text=textCtrl.GetValue()
        if len(text) == 0:
            dlg=wx.MessageBox(u"此处不能为空！", u"错误")
            textCtrl.SetBackgroundColour("pink")
            textCtrl.SetFocus()
            textCtrl.Refresh()
            return False
        else:
            textCtrl.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            textCtrl.Refresh()
            return True
    
    def TransferToWindow(self):
        return True
    
    def TransferFromWindow(self):
        return True
    

class OnIntValidator(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)
        
    def Clone(self):
        return OnIntValidator()

    def Validate(self,win):
        textCtrl=self.GetWindow()
        try:
            text=int(textCtrl.GetValue())
            if isinstance(text,int)==True:
                textCtrl.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
                textCtrl.Refresh()
                return True
        except ValueError:
            wx.MessageBox(u"请输入一个正确的数字", u"错误")
            textCtrl.SetBackgroundColour("pink")
            textCtrl.SetFocus()
            textCtrl.Refresh()
            return False
            
    def TransferToWindow(self):
        return True
    
    def TransferFromWindow(self):
        return True
            
        
    
class 	TimeLogic(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)
        
    def Clone(self):
        return TimeLogic()
    
    def Validate(self,win):
        textCtrl=self.GetWindow()
        text=textCtrl.GetValue()
        if len(text) == 0:
            dlg=wx.MessageBox(u"错误的时间逻辑，无法计算周期", u"错误")
            textCtrl.SetBackgroundColour("pink")
            #textCtrl.SetFocus()
            textCtrl.Refresh()
            return False
        else:
            textCtrl.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            textCtrl.Refresh()
            return True
    
    def TransferToWindow(self):
        return True
    
    def TransferFromWindow(self):
        return True